package com.nyist.springcloud.service.impl;

import cn.hutool.core.lang.UUID;
import com.nyist.springcloud.service.MessageProviderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;


/**
 * @author yangxiaogen
 * @date 2021/2/9 15:45
 */
@EnableBinding(Source.class)
@Slf4j
public class MessageProviderServiceServiceImpl implements MessageProviderService {

    //@Qualifier("nullChannel")
    //@Autowired
    // 不可以使用 Autowired 注解, 原因不明
    @Resource
    private MessageChannel output;

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        log.info("*********** serial" + serial);
        return null;
    }
}
